home *** CD-ROM | disk | FTP | other *** search
- unit DCOMSecUtils;
-
- interface
- uses Windows,ActiveX;
- const
- IID_IAccessControl : TGUID = '{EEDD23E0-8410-11CE-A1C3-08002B2B8D8F}';
-
- RPC_C_AUTHN_NONE = 0;
- RPC_C_AUTHN_DCE_PRIVATE = 1;
- RPC_C_AUTHN_DCE_PUBLIC = 2;
- RPC_C_AUTHN_DEC_PUBLIC = 4;
- RPC_C_AUTHN_WINNT = 10;
- RPC_C_AUTHN_DEFAULT = $FFFFFFFF;
-
- RPC_C_AUTHN_LEVEL_DEFAULT = 0;
- RPC_C_AUTHN_LEVEL_NONE = 1;
- RPC_C_AUTHN_LEVEL_CONNECT = 2;
- RPC_C_AUTHN_LEVEL_CALL = 3;
- RPC_C_AUTHN_LEVEL_PKT = 4;
- RPC_C_AUTHN_LEVEL_PKT_INTEGRITY = 5;
- RPC_C_AUTHN_LEVEL_PKT_PRIVACY = 6;
-
- RPC_C_AUTHZ_NONE = 0;
- RPC_C_AUTHZ_NAME = 1;
- RPC_C_AUTHZ_DCE = 2;
-
- RPC_C_IMP_LEVEL_ANONYMOUS = 1;
- RPC_C_IMP_LEVEL_IDENTIFY = 2;
- RPC_C_IMP_LEVEL_IMPERSONATE = 3;
- RPC_C_IMP_LEVEL_DELEGATE = 4;
-
- EOAC_NONE = $0;
- EOAC_DEFAULT = $800;
- EOAC_MUTUAL_AUTH = $1;
- EOAC_STATIC_CLOAKING = $20;
- EOAC_DYNAMIC_CLOAKING = $40;
- EOAC_ANY_AUTHORITY = $80;
- // These are only valid for CoInitializeSecurity
- EOAC_SECURE_REFS = $2;
- EOAC_ACCESS_CONTROL = $4;
- EOAC_APPID = $8;
- EOAC_MAKE_FULLSIC = $100;
- EOAC_REQUIRE_FULLSIC = $200;
- EOAC_AUTO_IMPERSONATE = $400;
- SEC_WINNT_AUTH_IDENTITY_ANSI = $1;
- SEC_WINNT_AUTH_IDENTITY_UNICODE = $2;
-
-
- type
- PCOAUTHIDENTITY = ^TCOAUTHIDENTITY;
- PShort = ^Short;
-
- TCOAUTHIDENTITY = record
- User : PShort; //UserName
- UserLength : ULONG;
- Domain : PShort; //DomainName
- DomainLength : ULONG;
- Password : PShort; //Password
- PasswordLength : ULONG;
- Flags : ULONG;
- end;
-
- TCoAuthInfo = record
- dwAuthnSvc : DWORD;
- dwAuthzSvc : DWORD;
- pwszServerPrincName : LPWSTR;
- dwAuthnLevel : DWORD ;
- dwImpersonationLevel : DWORD ;
- pAuthIdentityData : PCOAUTHIDENTITY;
- dwCapabilities : DWORD;
- end;
-
- IServerSecurity = interface(IUnknown)
- ['{0000013E-0000-0000-C000-000000000046}']
-
- function QueryBlanket
- (
- out AuthnSvc :DWORD;
- out AuthzSvc :DWORD;
- out ServerPrincName: POleStr;
- out AuthnLevel :DWORD;
- out ImpLevel : DWORD;
- out Privs : Pointer;
- out Capabilities : DWORD
- ) :HResult; stdcall;
- function ImpersonateClient :HResult; stdcall;
- function RevertToSelf :HResult; stdcall;
- function IsImpersonating :BOOL; stdcall;
- end;
-
-
- procedure SwitchSecurityOff(Authnlevel : boolean);
- function ClientBlanketInfo : string;
-
- // CoQueryClientBlanket was incorrectly defined !!!
- function CoQueryClientBlanket(var pwAuthnSvc, pAuthzSvc: Longint;
- var pServerPrincName: POleStr; var dwAuthnLevel, dwImpLevel: Longint;
- var pPrivs: Pointer; var dwCapabilites: Longint): HResult; stdcall;
-
- implementation
-
- uses Sysutils,ComObj;
- const
- ole32 = 'ole32.dll';
-
- function CoQueryClientBlanket; external ole32 name 'CoQueryClientBlanket';
-
- function ClientBlanketInfo : string;
- var
- P : PWideChar;
- ServerPrincName : PWidechar;
- PrincipalName : string;
- ClientName : string;
- AuthnSvc, AuthzSvc,Capabilit: Longint;
- AuthnLevel, ImpLevel: Longint;
-
- begin
- p := nil;
- Capabilit := EOAC_NONE;
- ServerPrincName := nil;
- OLECheck(CoQueryClientBlanket(AuthnSvc, AuthzSvc,
- ServerPrincName, AuthnLevel, ImpLevel, Pointer(P), Capabilit));
- ClientName := '';
- PrincipalName := '';
-
- if p <> nil then
- ClientName := WideCharToString(PWideChar(P));
-
- if ServerPrincName <> nil then
- begin
- PrincipalName := WideCharToString(ServerPrincName);
- CoTaskMemFree(ServerPrincName);
- end;
- Result := Format(' %s %s ',[PrincipalName, ClientName]);
- end;
-
- procedure SwitchSecurityOff(AuthnLevel : boolean);
- const
- AuthenticationLevel : array [boolean] of integer =
- (RPC_C_AUTHN_LEVEL_NONE, RPC_C_AUTHN_LEVEL_CONNECT);
- begin
- //if the authentication level is set to connect then the DCOM RPC will try to
- //make sure the user is part of the domain, so we really only want NONE
- //DCOM client, we need to call this before CCIEx
- //DCOM server, we need to call this before ClassFactory is instantiated
- OleCheck(CoInitializeSecurity(nil,-1,nil,nil,
- AuthenticationLevel[AuthnLevel],
- RPC_C_IMP_LEVEL_IMPERSONATE,nil,EOAC_NONE,nil));
-
- end;
-
-
-
- end.
-